<template>
  <div class="baseinfo">
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
      <a-row :gutter="24">
        <span style="margin-left:10px;font-size:24px">基本信息</span>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item label="项目编号" prop="projectNo" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            系统生成
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="projectName"
            label="项目名称"
            prop="projectName" 
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 16 }"
          >
            <a-input
              v-model="form.projectName"
              @blur="
                () => {
                  $refs.projectName.onFieldBlur()
                }
              "
              placeholder="请输入有效的项目名称"  
              :disabled="form.status>1" 
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="mainDeptName"
            label="项目承接主体"
            prop="mainDeptName"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input v-model="form.mainDeptName"  placeholder="请填写项目承接主体"  />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="项目分类"
            prop="projectTypeSubCategory" 
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.projectTypeSubCategory"
              placeholder="请选择项目分类"
              :options="projectCategoryOptions"  :disabled="form.id!=''"  
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="销值共享"
            prop="valueBelongs"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 16 }"
          >
            <a-select
              v-model="form.valueBelongs"
              placeholder="请选择"
              :options="valueBelongsOptions"
              @change="channelChange"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.valueBelongs == '是'">
          <a-form-model-item prop="valueShare" label="共享对象" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.valueShare"  placeholder="如有，请填写共享对象" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="公司跟进人员"
            prop="followUsername"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.followUsername"
              placeholder="请选择"
              @click="addFollow"
              read-only
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="渠道"
            prop="projectChannel"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 16 }"
          >
            <a-select
              v-model="form.projectChannel"
              placeholder="请选择"
              :options="basicInfo.projectChannelOptions"
              @change="channelChange"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="属性"
            prop="projectChannelType"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.projectChannelType"
              placeholder="请选择"
              :options="projectChannelTypeOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="类别"
            prop="projectChannelLevel"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.projectChannelLevel"
              placeholder="请选择"
              :options="basicInfo.projectChannelLevelOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <span style="margin-left:10px;font-size:24px">客户信息</span>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="16">
          <a-form-model-item
            ref="partnerName"
            label="合作对象"
            prop="partnerName"
            :label-col="{ span: 4 }"
            :wrapper-col="{ span: 20 }"
          >
            <a-input
              v-model="form.partnerName"
              @blur="
                  () => {
                    $refs.partnerName.onFieldBlur()
                  }
                "
              placeholder="请输入有效的合作对象"
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="单位性质"
            prop="partnerType"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.partnerType"
              placeholder="请选择"
              :options="basicInfo.partnerTypeOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item label="负责人" prop="leaderUsername" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请输入负责人" v-model="form.leaderUsername" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="负责人电话" prop="leaderPhone" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
            <a-input placeholder="请输入负责人电话" v-model="form.leaderPhone" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="注册资本/万" prop="registeredCapital" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
            <a-input placeholder="注册资本/万" type="number" min="0" max="999999" v-model="form.registeredCapitalSell" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="单位地址"
            prop="partnerAdressA"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-cascader :options="basicInfo.areaOptions" change-on-select @change="placeChange" v-model="form.partnerAdressA" placeholder="请选择区域" />
          </a-form-model-item>
        </a-col>
        <a-col :span="16">
          <a-form-model-item
            label="详细地址"
            prop="partnerAdressB"
            :label-col="{ span: 4 }"
            :wrapper-col="{ span: 20 }"
          >
            <a-input
              v-model="form.partnerAdressB"
              @blur="
                  () => {
                    $refs.partnerAdressB.onFieldBlur()
                  }
                "
              placeholder="请输入有效的地址"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <div><span style="font-size:18px;margin-top: 10px;">目前已合作食品类前三品牌</span></div>
        <div style="display: flex; margin-top: 10px; margin-bottom: 10px">
          <a-button type="primary" @click="partnerAdd()">新增</a-button>
          <a-button style="margin-right: 15px" class="default" @click="partnerDel()">删除</a-button>
        </div>
        <a-table :row-selection="rowSelection" :columns="partner.columns" :data-source="partner.data" bordered :key="partner.freshKey" :pagination="pagination">
          <template slot="name" slot-scope="text, record">
            <a-input v-model="record.name" :maxLength="500"/>
          </template>
          <template slot="sales" slot-scope="text, record">
            <a-input v-model="record.sales" type="number" min="0" max="9999999" :maxLength="500"/>
          </template>
        </a-table>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item label="年调味销售/使用额(万)" prop="flavouringYearSales" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写销售/使用额(万)" type="number" min="0" max="9999999" v-model="form.flavouringYearSales" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="年粮油销售/使用额(万)" prop="grainYearSales" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写销售/使用额(万)" type="number" min="0" max="9999999" v-model="form.grainYearSales" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <span style="margin-left:10px;font-size:24px">合作方式</span>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="供货模式"
            prop="deliveryModel"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.deliveryModel"
              placeholder="请选择"
              :options="basicInfo.deliveryModelOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.deliveryModel == '直供'">
          <a-form-model-item
            label="供货主体"
            prop="deliveryMain"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.deliveryMain"
              placeholder="请选择供货主体"
              :options="basicInfo.deliveryMainOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.deliveryModel == '非直供'">
          <a-form-model-item
            label="供货主体"
            prop="deliveryMain"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input placeholder="请填写供货主体" v-model="form.deliveryMain" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="所属区域"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-cascader :options="basicInfo.areaOptions" change-on-select @change="placeChange" v-model="form.responsibilityPlaceArr" placeholder="请选择区域" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" v-if="form.deliveryModel == '直供'">
        <a-col :span="8">
          <a-form-model-item label="海天专项资金/万" prop="specialFunds" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写资金"type="number" min="0" max="10000000" v-model="form.specialFunds" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="专项员工/人" prop="specialEmployee" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写人数" type="number" min="0" max="10000" v-model="form.specialEmployee" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="专项车辆/辆" prop="specialCar" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写用车数量" type="number" min="0" max="10000" v-model="form.specialCar" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" v-if="form.deliveryModel == '直供'">
        <a-col :span="8">
          <a-form-model-item label="是否曾与海天合作" prop="isCooperation" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-radio-group v-model="form.isCooperation">
              <a-radio value="true"> 是 </a-radio>
              <a-radio value="false"> 否 </a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.isCooperation == 'true'">
          <a-form-model-item label="曾合作多少年" prop="cooperationYear" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写时间/年" type="number" min="0" max="100" v-model="form.cooperationYear" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.isCooperation == 'true'">
          <a-form-model-item label="停止合作原因" prop="stopReason" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input placeholder="请填写原因" v-model="form.stopReason" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="产品组"
            prop="productGroup"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.productGroup"
              placeholder="请选择"
              :options="basicInfo.productGroupOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="物流模式" prop="logisticsModel" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-radio-group v-model="form.logisticsModel">
              <a-radio value="自建仓"> 自建仓 </a-radio>
              <a-radio value="共享云仓"> 共享云仓 </a-radio>
              <a-radio value="其他"> 其他 </a-radio>
            </a-radio-group>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item v-if="form.logisticsModel == '其他'" prop="logisticsModelOther" label="其他物流模式" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.logisticsModelOther"  placeholder="请填写其他物流模式" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <div><span style="font-size:18px;">合作目标/万元：</span></div>
          <div style="margin-top: 10px; margin-bottom: 10px;width:100%;">
            <a-table :row-selection="rowSelection"  :columns="target.columns" :data-source="target.data" bordered :key="target.freshKey" :pagination="pagination">
              <template v-for="(slotItem) of slots" :slot="slotItem" slot-scope="text, record">
                <a-form-model-item
                  :label-col="{ span: 1 }"
                  :wrapper-col="{ span: 23 }"
                  :validate-status="record[slotItem]+1 > 0 ? 'success':'error'"
                  :help="record[slotItem]+1 > 0 ? '':'请输入合作目标'"
                >
                <a-input v-model="record[slotItem]"  type="number" min="0" max="9999999999" />
                </a-form-model-item>
              </template>
            </a-table>
          </div>
        </a-col>
      </a-row>
      <a-row :gutter="24" v-if="form.deliveryModel=='直供'">
        <a-col :span="8">
          <a-form-model-item
            label="价格组"
            prop="priceGroup"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.priceGroup"
              placeholder="请选择"
              :options="basicInfo.priceGroupOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="返利模式"
            prop="rebateMode"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.rebateMode"
              placeholder="请选择"
              :options="basicInfo.rebateModeOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item v-if="form.rebateMode == '销值返利'" prop="rebateRate" label="占销值百分比（%）" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.rebateRate" type="number" min="0" max="100" placeholder="请填写返利利率" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item v-if="form.rebateMode == '其他方式'" prop="rebateWay" label="其他返利方式" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.rebateWay"  placeholder="请填写返利方式" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" v-if="form.deliveryModel=='直供'">
        <a-col :span="8">
          <a-form-model-item
            label="账期模式"
            prop="periodMode"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-select
              v-model="form.periodMode"
              placeholder="请选择"
              :options="basicInfo.periodModeOptions"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.periodMode == '银行授信' " >
          <a-form-model-item prop="bankName" label="银行名称" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.bankName"  placeholder="请填写银行名称" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.periodMode == '银行授信' || form.periodMode == '额度账期' " >
          <a-form-model-item prop="periodDays" label="账期天数" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.periodDays" type="number" min="0" max="100000" placeholder="请填写账期天数" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8" v-if="form.periodMode == '额度账期'">
          <a-form-model-item prop="periodLines" label="赊销额度/万" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            <a-input v-model="form.periodLines" type="number" min="0" max="100" placeholder="请填写赊销额度" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="21"  v-if="form.periodMode == '额度账期'">
          <a-form-model-item prop="periodMeasures" label="保证措施" :label-col="{ span: 3 }" :wrapper-col="{ span: 20 }">
            <a-textarea
              v-model="form.periodMeasures"
              @blur="
                () => {
                  $refs.periodMeasures.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 20 }"
              style="width: 100%"
              placeholder="请填写保证措施"
            ></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="21"  v-if="form.periodMode == '额度账期'">
          <a-form-model-item prop="periodDescription" label="原因说明" :label-col="{ span: 3 }" :wrapper-col="{ span: 20 }">
            <a-textarea
              v-model="form.periodDescription"
              @blur="
                () => {
                  $refs.periodDescription.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 20 }"
              style="width: 100%"
              placeholder="请填写原因说明"
            ></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item
            ref="remark"
            label="其他"
            prop="remark"
            :label-col="{ span: 3 }"
            :wrapper-col="{ span: 20 }"
          >
            <a-textarea
              v-model="form.remark"
              @blur="
                () => {
                  $refs.remark.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 10 }"
              style="width: 100%"
              placeholder="项目收益分析、项目必要性说明或其他，自由填写（1000字以内）"
            ></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>
      <five-to-five ref="fiveForm" :projectBuildId="projectBuildId" :change-id="changeId" @addField="addFiveDataToForm"/>
    </a-form-model>
    <person-select ref="personSelect" @setPersonSelResult="setPersonSelResult" :limit="personLimit"/>
  </div>
</template>
<script>
import $ from 'jquery'
import { getAction, getActionAsync, postAction, postActionAsync } from '@/api/manage'
import { getParamValFromUrl, strNotNull } from '@/utils/common.js'
import JTreeSelect from '@/components/jeecg/JTreeSelect'
import Vue from 'vue'
export default {
  components: {
    PaginationSelect: () => import('@/components/tools/PaginationSelect'),
    PersonSelect: () => import('@/components/tools/PersonSelect'),
    JTreeSelect,
    FiveToFive: () => import('@/components/tools/projectBuildStup/baseInfo/FiveToFive')
  },
  props: {
    projectBuildId: {
      Type: String,
      default: '',
    },
    changeId: {
      Type: String,
      default: '',
    }
  },
  data() {
    return {
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      other: '',
      userSel: {
        tabUrl: '/upms/user/selPersonList',
        title:'',
        visible: false,
        confirmLoading: true,
        keyword: '',
        userSelectData:[],
        data: [],
        freshKey: 0,
        selectUserData:[],
        currentRecord:null,
        selectPersonType:'follow',
        selectItem:null
      },
      personLimit:0,
      form: {
        id: '',
        projectClass: '90',
        projectNo: '',
        projectName: '',
        mainDeptId: '',
        mainDeptName: '',
        projectTypeSubCategory: '',
        valueBelongs:'',
        valueShare:'',
        followUserid:'',
        followUsername:'',
        projectChannel:'',
        projectChannelType:'',
        projectChannelLevel:'',
        partnerName:'',
        partnerType:'',
        leaderUserid:'',
        leaderUsername:'',
        leaderPhone:'',
        registeredCapitalSell:'',
        partnerAdress:'',
        warehouseAdress:'',
        specialFunds:'',
        specialEmployee:'',
        specialCar:'',
        isCooperation:'',
        cooperationYear:'',
        stopReason:'',
        productGroup:'',
        priceGroup:'',
        rebateMode:'',
        rebateRate:'',
        rebateWay:'',
        periodMode:'',
        periodDays:'',
        periodLines:'',
        periodMeasures:'',
        periodDescription:'',
        flavouringYearSales:'',
        grainYearSales:'',
        cooperateTarget:'',
        responsibilityPlace:'',
        deliveryModel:'',
        deliveryMain:'',
        logisticsModel:'',
        logisticsModelOther:'',
        projectChannelArea:'',
        remark:'',
        partnerVOList:[],
        targetVOList:[],
        responsibilityPlaceArr:[],
        bankName:'',
        partnerAdressA:'',
        partnerAdressB:'',
        status: 0 
      },
      flag:false,
      pagination:false,
      userSel: {
        tabUrl: '/upms/user/selUserListWithNoLock',
        title:'',
        visible: false,
        visibleFunc: false,
        confirmLoading: true,
        keyword: '',
        colums: [
          {
            title: '用户名',
            dataIndex: 'username',
            align:'center',
            scopedSlots: { customRender: 'username' }
          },
          {
            title: '姓名',
            dataIndex: 'realname',
            align:'center',
            scopedSlots: { customRender: 'realname' }
          },
          {
            title: '部门',
            dataIndex: 'orgCodeTxt',
            align: 'center',
            scopedSlots: { customRender: 'orgCodeTxt' }
          }
        ],
        data: [],
        freshKey: 0,
        deptManagerUserData:[],
        functionDepartmentUserData:[]
      },
      basicInfo:{
        projectChannelTypeList:[],
        projectChannelOptions:[],
        projectChannelLevelOptions:[],
        areaOptions:[],
        deliveryModelOptions:[],
        targetColumns:[],
        valueBelongsOptions:[],
        productGroupOptions:[],
        priceGroupOptions:[],
        rebateModeOptions:[],
        periodModeOptions:[],
        partnerTypeOptions:[],
        deliveryMainOptions:[]
      },
      projectChannelTypeOptions:[],
      partner:{
        columns:[
          {
            title: '合作品牌',
            dataIndex: 'name',
            width: '30%',
            scopedSlots: { customRender: 'name' },
          },
          {
            title: '年销售额/万',
            dataIndex: 'sales',
            scopedSlots: { customRender: 'sales' },
          },
        ],
        data:[],
        selRowIds:[],
        freshKey:0
      },
      target:{
        columns:[],
        data:[],
        selRowIds:[],
        freshKey:0
      },
      slots:[],
      rules: {
        projectName: [
          { required: true, message: '请输入有效的项目名', trigger: 'blur' },
          { min: 1, max: 50, message: '项目名不超过50个字符', trigger: 'blur' },
        ],
        valueShare: [
          { required: true, message: '请输入有效的销值共享对象', trigger: 'blur' },
          { min: 1, max: 50, message: '名称不超过50个字符', trigger: 'blur' },
        ],
        partnerName: [
          { required: true, message: '请输入有效的合作对象', trigger: 'blur' },
          { min: 1, max: 50, message: '名称不超过50个字符', trigger: 'blur' },
        ],
        cooperateTarget: [
          { required: true, message: '请输入合作目标/万元', trigger: 'blur' },
          { min: 1, max: 15, message: '数额不超过15位', trigger: 'blur' },
        ],
        mainDeptName: [
          { required: true, message: '请输入主导经营体', trigger: 'blur' },
          { min: 1, max: 300, message: '主导经营体不超过300个字符', trigger: 'blur' },
        ],
        followUsername: [
          { required: true, message: '请选择跟进人员', trigger: 'blur' },
          { min: 1, max: 300, message: '跟进人员不超过300个字符', trigger: 'blur' },
        ],
        leaderUsername: [
          { required: true, message: '请填写负责人', trigger: 'blur' },
          { min: 1, max: 20, message: '负责人名称不超过20个字符', trigger: 'blur' },
        ],
        leaderPhone: [
          { required: true, message: '请填写负责人电话', trigger: 'blur' },
          { min: 11, max: 11, message: '负责人电话必须为11位', trigger: 'blur' },
        ],
        registeredCapitalSell: [
          { required: true, message: '请填写注册资本', trigger: 'blur' },
          { min: 1, max: 10, message: '注册资本不超为10位数', trigger: 'blur' },
        ],
        partnerAdressB: [
          { required: true, message: '请填写详细地址', trigger: 'blur' },
          { min: 1, max: 300, message: '详细地址不超过300个字符', trigger: 'blur' },
        ],
        warehouseAdress: [
          { required: true, message: '请填写仓库地址', trigger: 'blur' },
          { min: 1, max: 300, message: '仓库地址不超过300个字符', trigger: 'blur' },
        ],
        specialFunds: [
          { required: false, message: '请填写海天专项资金', trigger: 'blur' },
          { min: 1, max: 10, message: '海天专项资金不超过10位数', trigger: 'blur' },
        ],
        specialEmployee: [
          { required: false, message: '请填写海天专项员工', trigger: 'blur' },
          { min: 1, max: 6, message: '海天专项员工不超过六位数', trigger: 'blur' },
        ],
        specialCar: [
          { required: false, message: '请输入海天专项车辆', trigger: 'blur' },
          { min: 1, max: 6, message: '海天专项车辆不超过六位数', trigger: 'blur' },
        ],
        target: [
          { required: false, message: '请输入合作目标', trigger: 'blur' },
          { min: 1, max: 10, message: '合作目标不超过10位数', trigger: 'blur' },
        ],
        periodDays: [
          { required: true, message: '请输入账期天数', trigger: 'blur' },
          { min: 1, max: 10, message: '账期天数不超过10位数', trigger: 'blur' },
        ],
        periodLines: [
          { required: true, message: '请输入赊销额度', trigger: 'blur' },
          { min: 1, max: 10, message: '赊销额度不超过10位数', trigger: 'blur' },
        ],
        periodMeasures: [
          { required: true, message: '请输入保证措施', trigger: 'blur' },
          { min: 1, max: 200, message: '保证措施不超过10字', trigger: 'blur' },
        ],
        periodDescription: [
          { required: true, message: '请输入原因说明', trigger: 'blur' },
          { min: 1, max: 200, message: '原因说明不超过200字', trigger: 'blur' },
        ],
        rebateWay: [
          { required: true, message: '请输入其他返利方式', trigger: 'blur' },
          { min: 1, max: 200, message: '原因说明不超过200字', trigger: 'blur' },
        ],
        bankName: [
          { required: true, message: '请输入银行名称', trigger: 'blur' },
          { min: 1, max: 100, message: '银行名称不超过200字', trigger: 'blur' },
        ],
        cooperationYear: [
          { required: true, message: '请输入曾合作多少年', trigger: 'blur' },
          { min: 1, max: 10, message: '年数不超过10位', trigger: 'blur' },
        ],
        stopReason: [
          { required: true, message: '请输入停止合作原因', trigger: 'blur' },
          { min: 1, max: 100, message: '停止合作原因不超过100字', trigger: 'blur' },
        ],
        logisticsModelOther: [
          { required: true, message: '请输入其他物流模式', trigger: 'blur' },
          { min: 1, max: 100, message: '其他物流模式不超过100字', trigger: 'blur' },
        ],


        valueBelongs: [{ required: true, message: '请选择', trigger: 'change' }],
        projectTypeSubCategory: [{ required: true, message: '请选择项目分类', trigger: 'change' }],
        projectChannel: [{ required: true, message: '请选择渠道', trigger: 'change' }],
        projectChannelType: [{ required: true, message: '请选择属性', trigger: 'change' }],
        projectChannelLevel: [{ required: true, message: '请选择类别', trigger: 'change' }],
        partnerType: [{ required: true, message: '请选择单位性质', trigger: 'change' }],
        logisticsModel: [{ required: true, message: '请选择物流模式', trigger: 'change' }],
        deliveryModel: [{ required: true, message: '请选择供货模式', trigger: 'change' }],
        deliveryMain: [{ required: true, message: '请选择供货主体', trigger: 'change' }],
        isCooperation: [{ required: true, message: '请选择是否曾与海天合作', trigger: 'change' }],
        productGroup: [{ required: true, message: '请选择产品组', trigger: 'change' }],
        priceGroup: [{ required: true, message: '请选择价格组', trigger: 'change' }],
        rebateMode: [{ required: true, message: '请选择返利模式', trigger: 'change' }],
        periodMode: [{ required: true, message: '请选择账期模式', trigger: 'change' }],
        partnerAdressA: [{ required: true, message: '请选择单位地址', trigger: 'change' }]
      },
      follow: {
        visible: false,
        title: '请选择跟进人员',
        searchPlaceholder: '输入名称查询',
        url: '/sys/user/list',
        columns: [
          {
            title: '用户账户',
            dataIndex: 'username',
            align: 'center',
          },
          {
            title: '用户名称',
            dataIndex: 'realname',
            align: 'center',
          },
        ],
      },
      projectCategoryOptions: [],
      valueBelongsOptions:[
        {
          key:1,
          label:"否",
          value:"否"
        },
        {
          key:2,
          label:"是",
          value:"是"
        }
      ],
      url: {
        codeInfoList: '/manage/codeInfo/list',
        getProjectByNo: '/projectBuild/getProjectByNo',
        save: '/projectBuild/add',
        queryVOById: '/projectBuild/queryVOById',
        getBasicInfo: '/projectBuild/getBasicInfo'
      },
      loadFinish: false

    }
  },
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.partner.selRowIds=selectedRowKeys;
        }
      }
    },
  },
  methods: {
    addFiveDataToForm(val,valRef) {
      this.$set(this.form, valRef, val)
    },
    async doSubmit() {
      if(!this.loadFinish){
        layer.message.warning('请等待页面加载完毕')
        return {}  
      }
      var validR=false;
      try{
        validR = await this.$refs.ruleForm.validate();
        validR = await this.$refs.fiveForm.checkFiveWriteStatus()
      }catch(e){
        validR = false;
      }
      console.log('validR',validR);
      this.form.validResult = validR;
      let res=await this.doSave();
      this.projectBuildId=res;
      return {valid:validR,id:res};
    },
    async doSave() {
      let flag=null;
      var vm = this
      this.form.partnerVOList = this.partner.data;
      this.form.targetVOList = [];
      this.form.targetVOList.push(this.target.data[0]);
      if(this.form.periodMode == '银行授信'){
        this.form.periodMeasures = this.form.bankName;
      }
      this.form.responsibilityPlace = '';
      if(this.form.responsibilityPlaceArr != null && this.form.responsibilityPlaceArr.length > 0){
        this.form.responsibilityPlaceArr.forEach(item =>{
          this.form.responsibilityPlace += item + " / ";
        })
        this.form.responsibilityPlace = this.form.responsibilityPlace.substring(0,this.form.responsibilityPlace.length-3);
      }
      this.form.changeId=this.changeId;
      this.form.partnerAdress = '';
      if(this.form.partnerAdressA.length>0){
        this.form.partnerAdressA.forEach(item =>{
          this.form.partnerAdress += item + " / ";
        })
      }
      this.form.partnerAdress = this.form.partnerAdress.substring(0,this.form.partnerAdress.length-3);
      this.form.partnerAdress = this.form.partnerAdress + "-" + this.form.partnerAdressB;
      await postActionAsync(this.url.save, this.form)
        .then((res) => {
          if (res.code == 200) {
            vm.form.id = res.result.id;
            this.$message.success('保存成功')
            vm.initData();
            return flag=res.result.id;
          } else {
            this.$message.warning('保存数据出错:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('保存数据出错:' + res.message)
        })
        return flag;
    },
    resetForm() {
      this.$refs.ruleForm.resetFields()
    },
    //初始化项目子类
    initProjectCategoryOptions() {
      var vm = this
      getAction(this.url.codeInfoList, { type: '项目子类', isdel: 0, parentid: vm.form.projectClass })
        .then((res) => {
          if (res.code == 200) {
            var list = res.result
            if (list != null) {
              list.records.map((item) => {
                vm.projectCategoryOptions.push({ value: item.code, label: item.name })
              })
            }
          } else {
            this.$message.warning('查询项目子类失败:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('查询项目子类失败:' + res.message)
        })
    },
    //校验上一代项目号
    checkPreProject() {
      if (this.form.lastProjectNo != null && this.form.lastProjectNo.length > 0) {
        var vm = this
        getAction(this.url.getProjectByNo, { projectNo: this.form.lastProjectNo })
          .then((res) => {
            if (res.code == 200) {
              var result = res.result
              if (result != null) {
                this.form.lastProjectName = result.projectName
              } else {
                this.form.lastProjectNo = ''
                vm.$message.warning('请输入有效的【上一代项目号】')
              }
            } else {
              this.$message.warning('查询上一代项目失败:' + res.message)
            }
          })
          .catch((res) => {
            this.$message.warning('查询上一代项目失败:' + res.message)
          })
      }
    },
    //渠道变化，变更属性选项
    channelChange() {
      let projectChannel = this.form.projectChannel;
      this.basicInfo.projectChannelTypeList.forEach(item =>{
        if(item.projectChannel == projectChannel){
          this.projectChannelTypeOptions = item.projectChannelTypeOptions;
        }
      })
    },
    //如果有id，则加载已填写信息
    initData() {
      if (this.projectBuildId != null && this.projectBuildId != '') {
        var vm = this
        getAction(this.url.queryVOById, { id: this.projectBuildId,changeId:this.changeId })
          .then((res) => {
            if (res.code == 200) {
              var result = res.result
              if (result != null) {
                this.form = result;
                this.partner.data = result.partnerVOList;
                this.target.data = result.targetVOList;
                if(this.form.periodMode == '银行授信'){
                  this.form.bankName = this.form.periodMeasures;
                }
                if(this.form.responsibilityPlace != null && this.form.responsibilityPlace.indexOf('/') > 0){
                  this.form.responsibilityPlaceArr = this.form.responsibilityPlace.split(' / ');
                }
                if(this.form.partnerAdress != null && this.form.partnerAdress.indexOf('-')>0){
                  this.form.partnerAdressA = this.form.partnerAdress.split('-')[0].split(' / ');
                  this.form.partnerAdressB = this.form.partnerAdress.split('-')[1];
                }
                if(this.form.isCooperation){
                  this.form.isCooperation = "true";
                }else{
                  this.form.isCooperation = "false"
                }

                this.channelChange();
                this.loadFinish=true
              } else {
                vm.$message.warning('初始化项目信息为空')
              }
            } else {
              this.$message.warning('初始化项目信息失败:' + res.message)
            }
          })
          .catch((res) => {
            this.$message.warning('初始化项目信息失败:' + res.message)
          })
      }else{
        this.targetAdd();
        this.loadFinish=true
      }
    },
    title: '合作品牌',
    dataIndex: 'name',
    width: '30%',
    getBasicInfo(){
      getAction(this.url.getBasicInfo, {  })
        .then((res) => {
          if (res.code == 200) {
            var result = res.result
            if (result != null) {
              this.basicInfo = res.result;
              this.form.mainDeptName = this.basicInfo.mainDeptName;
              let targetColumns = res.result.targetColumns;
              targetColumns.forEach(item =>{
                let col = {};
                col.title = item.label;
                col.dataIndex = item.value;
                col.width = item.parentid;
                col.scopedSlots = {customRender: item.value};
                this.target.columns.push(col);
              })
              for (let column of this.target.columns) {
                if (column.scopedSlots && column.scopedSlots.customRender) {
                  this.slots.push(column.scopedSlots.customRender)
                }
              }

              if(this.form.projectChannel){
                let projectChannel = this.form.projectChannel;
                this.basicInfo.projectChannelTypeList.forEach(item =>{
                  if(item.projectChannel == projectChannel){
                    this.projectChannelTypeOptions = item.projectChannelTypeOptions;
                  }
                })
              }
            }
          } else {
            this.$message.warning('初始化信息失败:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('初始化信息失败:' + res.message)
        })
    },
    targetAdd(){
      if(this.target.data.length==1 || this.target.data.length>1){
        return;
      }
      this.target.data.push({
        key:this.target.data.length + 1 + new Date().getTime(),
        type:'target'
      })
    },
    partnerAdd() {
      if(this.partner.data.length == 3){
        this.$message.warning('仅需要填写前三品牌，无需再增加');
        return;
      }
      this.partner.data.push({
        key: this.partner.data.length + 1+new Date().getTime(),
        type:'sales',
        name: '',
        fiscal: '',
        fales: '',
      })
    },
    partnerDel() {
      if(this.partner.selRowIds.length==0){
        this.$message.warning('请选择要删除的品牌记录');
        return;
      }
      for(var i=0;i<this.partner.selRowIds.length;i++){
        for(var j=this.partner.data.length-1;j>=0;j--){
          if(this.partner.data[j].key==this.partner.selRowIds[i]){
            this.partner.data.splice(j,1);
            break;
          }
        }
      }
      this.partner.selRowIds=[];
      this.partner.freshKey++;
    },
    //孵化项目选中
    followHandleOk(record) {
      if (record != null && record.length > 0) {
        record.forEach(item =>{
          this.form.follow_userid += item.username + ",";
          this.form.follow_username += item.realname + ",";
        })
        this.form.follow_userid.substring(0,this.form.follow_userid.length-2);
        this.form.follow_username.substring(0,this.form.follow_username.length-2);
      }
      this.follow.visible = false
    },
    getSelUserData(){
      getAction(this.userSel.tabUrl,{pageSize:10000}).then(res=>{
        if(res.code==0){
          this.userSel.userSelectData=res.result.records;
        }else{
          this.$message.warning('用户选择数据加载失败:'+res.message);
        }
      })
    },
    addFollow(){
      this.userSel.selectPersonType='follow';
      this.personLimit=0;
      this.$refs.personSelect.doSelect();
    },
    setPersonSelResult(result){
      debugger;
      let followUsername = '';
      let followUserId = '';
      if(this.userSel.selectPersonType==='follow'){
        for(let i=0;i<result.length;i++){
          let item = result[i];
          followUserId += item.username + ",";
          followUsername += item.realname + ",";
        }
      }
      this.form.followUserid = followUserId.substring(0,followUserId.length-1);
      this.form.followUsername = followUsername.substring(0,followUsername.length-1);
    },
    renderItem(item) {
      const customLabel = (
        <span class="custom-item">
        {item.username} - {item.realname}
    </span>
    );
      return {
        label: customLabel, // for displayed item
        value: item.username, // for title and filter matching
      };
    },
    SelectDeptManager(targetKeys, direction, moveKeys) {
      this.userSel.deptManagerUserData=targetKeys
    },
    SelectDepartmentUser(targetKeys, direction, moveKeys) {
      this.userSel.functionDepartmentUserData = targetKeys
    },
    placeChange(value){

    },
  },
  mounted() {
    this.initProjectCategoryOptions()
    this.getBasicInfo()
    this.getSelUserData
    this.initData()
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-btn-primary {
  width: 85px;
  height: 30px;
  border-radius: 2px;
  background: #4095e4;
  margin-right: 10px;
}
/deep/ .default {
  width: 85px;
  height: 30px;
  border-radius: 2px;
}
.baseinfo {
  background-color: #fff;
  border: 1px solid #eaeaea;
  padding: 30px;
  .btn {
    display: flex;
    justify-content: center;
  }
}
</style>